# app/__init__.py
from flask import Flask

from app.Controller.AdminController import admin_bp
from app.Controller.ClassificationController import classification_bp
from app.Controller.OrderController import order_bp
from app.Controller.ThingController import thing_controller
from app.Controller.UserController import user_bp

from app.db import db, init_database


def create_app():
    app = Flask(__name__)
    app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:050824@localhost:3306/pyshop'
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

    # 初始化数据库
    init_database(app)

    # 注册蓝图

    app.register_blueprint(thing_controller, url_prefix='/myapp/admin/thing')
    app.register_blueprint(order_bp, url_prefix='/myapp/admin/order')
    app.register_blueprint(classification_bp, url_prefix='/myapp/admin/classification')
    app.register_blueprint(user_bp, url_prefix='/user')
    app.register_blueprint(admin_bp, url_prefix='/admin')

    return app